//
//  PositionStack.m
//  midiApp
//
//  Created by Laurent Novac on 25.02.11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PositionStack.h"
#import "Position.h"

@implementation PositionStack
@synthesize stack;

/*--------------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------INIT--------------------------------------------------------------------------------------------------*/

-(id)init{
	self=[super init];
	if(self){
		stack=[[NSMutableArray alloc]init];
	}
	return self;
}

/*--------------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------STACK OPERATIONS----------------------------------------------------------------------------------*/

-(void)pushToHead:(Position*) pos{
	[stack addObject:pos];//at object at the end (head)
}
-(Position*)popFromHead{
	Position* p;
	p=[stack lastObject];//get the head of the stack
	return p;
}
-(void)emptyStack{
	[stack removeAllObjects];
}
-(void)logStack{//log the entire queue
	NSEnumerator* enumerator=[stack objectEnumerator];
	Position* pos;
	while (pos=[enumerator nextObject]) {
		NSLog([NSString stringWithFormat:@"x: %.2f y: %.2f \n",[pos pos].x,[pos pos].y]);
	}
}

/*--------------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------------------------MEMORY MANAGEMENT---------------------------------------------------------------------------------*/

-(void)dealloc{
	[stack release];
	[super dealloc];
}

@end
